package org.example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.model.Result;
import org.example.service.SendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@Api(tags = "微信小程序短信业务接口管理")
@RequestMapping("/p/sms")
@RestController
public class SendController {

    @Autowired
    private SendService sendService;

    @ApiOperation("获取短信验证码")
    @PostMapping("/send")
    public Result<String> sendPhoneMsg(@RequestBody Map<String, Object> map) {
        // 调用阿里云短信发送接口
        // sendService.sendAliyunPhoneMsg(map);
        // 调用自己写的短信发送接口
        sendService.sendPhoneMsg(map);
        return Result.success( "短信发送成功");
    }

    @ApiOperation("绑定手机号码")
    @PostMapping("/savePhone")
    public Result<String> saveMsgPhone(@RequestBody Map<String, Object> map) {
        Boolean saved = sendService.saveMsgPhone(map);
        return Result.handle( saved);
    }

}
